﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Com.CMS263.PO;

namespace Com.CMS263.DAO
{
    public class JobsDAO
    {
        public JobsDAO() { }

        public bool Add(Jobs Jobs)
        {
            try
            {
                DBHelper.TransSaveOrUpdate(Jobs);
                return true;
            }
            catch
            {
                return false;
            }
        }
        public Jobs GetJobsById(int id)
        {
            try
            {
                return DBHelper.ExecuteHQL("from Jobs where id=" + id).List<Jobs>().First();
            }
            catch
            {
                return null;
            }
        }
        public IList<Jobs> GetAllJobs()
        {
            return null;
        }
        public bool ModifyJobs(Jobs Jobs)
        {
            try
            {
                DBHelper.TransUpdate(Jobs);
                return true;
            }
            catch
            {
                return false;
            }
        }
        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="pageSize"></param>
        /// <param name="currentIndex"></param>
        /// <param name="type">0是社会招聘，1是校园招聘</param>
        /// <returns></returns>
        public IList<Jobs> GetJobsPaging(int pageSize, int currentIndex,int type)
        {
            return DBHelper.ExecuteHQL("from Jobs where JobType="+type+" order by AddDate desc").SetFirstResult((currentIndex - 1) * pageSize).SetMaxResults(pageSize).List<Jobs>();
        }
        public bool DeleteJobsById(int id)
        {
            try
            {
                DBHelper.ExecuteHQL("delete from Jobs as di where di.id=" + id).ExecuteUpdate();
                return true;
            }
            catch
            {
                return false;
            }
        }
        public bool DeleteJobsByIds(string ids)
        {
            try
            {
                DBHelper.ExecuteHQL("delete from Jobs as di where di.id in(" + ids + ")").ExecuteUpdate();
                return true;
            }
            catch
            {
                return false;
            }
        }
        public int GetTotal(int type)
        {

            return Convert.ToInt32(DBHelper.ExecuteHQL("select count(*) from Jobs where JobType="+type).UniqueResult());

        }
    }
}
